package cn.xm.lingshi.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.xm.lingshi.pojo.DingDan;
import cn.xm.lingshi.pojo.GouWuChe;
import cn.xm.lingshi.pojo.User;
import cn.xm.lingshi.pojo.YongHu;
import cn.xm.lingshi.service.CartService;
import cn.xm.lingshi.service.OrderService;
import cn.xm.lingshi.service.impl.CartServiceImpl;
import cn.xm.lingshi.service.impl.OrderServiceImpl;

public class CartServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	
	public void destroy() {
		super.destroy(); 
		
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		CartService order=new CartServiceImpl();
		//String type=request.getParameter("type");
		YongHu user=(YongHu)request.getSession().getAttribute("denglu");
		String id="0";
		
		if(user!=null){
			GouWuChe list= order.queryRecord(0,10, user.getUserId());
			out.print(JSON.toJSONString(list));
			request.getSession().setAttribute("cart", list);
		}else{
			
			out.print(JSON.toJSONString(id));
		}
		
		//request.getSession().setAttribute("order", list);
		//response.sendRedirect("/lingshi/pt_houtai.jsp");
		out.flush();
		out.close();
	}

	
	public void init() throws ServletException {
		
	}

}
